#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
#include <locale.h>
#include <arpa/inet.h>
#define MAX_LINE 1024

int main()
{
	setlocale(LC_ALL,"zh_CN.utf-8");
	char buf[200][MAX_LINE]={'\0'};
	FILE *fp;
	int len;
	int i = 0;
	if((fp = fopen("world.txt", "r")) == NULL){ /* 打开文件 */
		cout<<"fail to read"<<endl;
	}
	while(fgets(buf[i], MAX_LINE, fp) != NULL){
		//cout<<buf[i]<<endl;
			i++;			
	}
	cout<<"Begin: "<<endl;
	for (int count=0;count<i;count++)
	{   
		cout<<"NO:"<<count<<"\t"<<buf[count]<<endl;
	}
	cout<<"--------------"<<endl;
	cout<<"MultiChar Sort: "<<endl;
	int m;
	int n;
	char temp[MAX_LINE];
    //cout<<i<<endl;
	for(m=0;m<i-1;m++)
	{
	  for(n=0;n<i-1-m;n++)
	  {
		  if (strcoll(buf[n],buf[n+1])>0)
		  {
		      strcpy(temp,buf[n]);
			  strcpy(buf[n],buf[n+1]);
			  strcpy(buf[n+1],temp);
		  }
	  }
	
	}
   for(int count=0;count<i;count++)
   {
		   printf("%d:\t %X %s", count,  htonl(*(int*)buf[count]), buf[count]);	
   }
   //fclose(fp);
}

